from django.shortcuts import render

from publisher.models import Publisher


# Create publisher views here.


def publisher_detail(request, pid):
    """ 依据 pid 获取出版社 """
    publisher = Publisher.objects.get(id=pid)

    # 补充：查找出该出版社出版的所有书
    books = publisher.book_set.all()  # 这个也可以直接在前端写，但是all不要加括号
    context = {
        'publisher': publisher,
        'books': books,
    }
    return render(request, 'publisher/publisher-detail.html', context)

